package com.herch.web.controller.common;

import com.herch.common.core.domain.AjaxResult;
import com.herch.system.domain.vo.SerialPortVo;
import com.herch.system.service.SerialPortService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
import java.util.Map;

/**
 * @Author: fei.li02
 * @Date: 2023/7/10 16:54
 * @Description:串口通讯
 */
@Controller
@RequestMapping("/comm/serialPort")
public class SerialPortController {
    @Autowired
    private SerialPortService serialPortService;

    @RequestMapping("/findPorts")
    @ResponseBody
    public List<String> selectPorts(){
        // 串口列表
        List<String> mCommList = serialPortService.findPorts();
        return mCommList;
    }
    @RequestMapping("/open")
    @ResponseBody
    public AjaxResult openPort(@RequestBody SerialPortVo serialPortVo) {
        Map<String, Object> resultMap = serialPortService.openPort(serialPortVo);
        return AjaxResult.success(resultMap);
    }
    @RequestMapping("/close")
    @ResponseBody
    public AjaxResult closePort() {
        Map<String, Object> msg = serialPortService.closePort();
        return AjaxResult.success(msg);
    }
}
